package org.jeecg.modules.electricity.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.basic.demo.apartment.service.ILwgyBaseApartmentService;
import org.jeecg.modules.elecrecord.entity.LwgyElecRecord;
import org.jeecg.modules.elecrecord.service.ILwgyElecRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 房间电量记录表
 * @Author: jeecg-boot
 * @Date:   2021-05-26
 * @Version: V1.0
 */
@Api(tags="房间电量记录表")
@RestController
@RequestMapping("/elec/lwgyElecRecord")
@Slf4j
public class LwgyMeterRecordController extends JeecgController<LwgyElecRecord, ILwgyElecRecordService> {
	@Autowired
	private ILwgyElecRecordService lwgyElecRecordService;

	@Resource
	private ILwgyBaseApartmentService lwgyBaseApartmentService;
	/**
	 * 分页列表查询
	 *
	 * @param lwgyElecRecord
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "房间电量记录表-分页列表查询")
	@ApiOperation(value="房间电量记录表-分页列表查询", notes="房间电量记录表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(LwgyElecRecord lwgyElecRecord,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<LwgyElecRecord> queryWrapper = QueryGenerator.initQueryWrapper(lwgyElecRecord, req.getParameterMap());
		Page<LwgyElecRecord> page = new Page<LwgyElecRecord>(pageNo, pageSize);
		IPage<LwgyElecRecord> pageList = lwgyElecRecordService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 *   添加
	 *
	 * @param lwgyElecRecord
	 * @return
	 */
	/*@AutoLog(value = "房间电量记录表-添加")
	@ApiOperation(value="房间电量记录表-添加", notes="房间电量记录表-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody LwgyWaterRecord lwgyElecRecord) {
		lwgyElecRecordService.save(lwgyElecRecord);
		return Result.OK("添加成功！");
	}
*/
	/**
	 *  编辑
	 *
	 * @param lwgyElecRecord
	 * @return
	 */
/*	@AutoLog(value = "房间电量记录表-编辑")
	@ApiOperation(value="房间电量记录表-编辑", notes="房间电量记录表-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody LwgyWaterRecord lwgyElecRecord) {
		lwgyElecRecordService.updateById(lwgyElecRecord);
		return Result.OK("编辑成功!");
	}*/

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
/*	@AutoLog(value = "房间电量记录表-通过id删除")
	@ApiOperation(value="房间电量记录表-通过id删除", notes="房间电量记录表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		lwgyElecRecordService.removeById(id);
		return Result.OK("删除成功!");
	}*/

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
/*	@AutoLog(value = "房间电量记录表-批量删除")
	@ApiOperation(value="房间电量记录表-批量删除", notes="房间电量记录表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.lwgyElecRecordService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}*/

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
/*	@AutoLog(value = "房间电量记录表-通过id查询")
	@ApiOperation(value="房间电量记录表-通过id查询", notes="房间电量记录表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		LwgyWaterRecord lwgyElecRecord = lwgyElecRecordService.getById(id);
		if(lwgyElecRecord==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(lwgyElecRecord);
	}*/

    /**
    * 导出excel
    *
    * @param request
    * @param lwgyElecRecord
    */
/*
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, LwgyWaterRecord lwgyElecRecord) {
        return super.exportXls(request, lwgyElecRecord, LwgyWaterRecord.class, "房间电量记录表");
    }
*/

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
   /* @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, LwgyElecRecordRecord.class);
    }

	 *//**
	  *   接收电控系统传递过来的数据
	  *
	  * @param json
	  * @return
	  *//*
	 @AutoLog(value = "接收电控系统传递过来的数据")
	 @ApiOperation(value="接收电控系统传递过来的数据", notes="接收电控系统传递过来的数据")
	 @PostMapping(value = "/submit")
	 public Result<?> add(@RequestBody List<Map> json) {
	 	 log.error(">>>>>>>>>>>>>>>接收数据"+json.toString());

		 return Result.OK("接收成功！");
	 }

	 *//**
	  *   构建各个楼宇的电量数据
	  * @param
	  * @return
	  *//*
	 @AutoLog(value = "各个楼宇的电量数据")
	 @ApiOperation(value="各个楼宇的电量数据", notes="各个楼宇的电量数据")
	 @PostMapping(value = "/buildElectricityData")
	 public Result<?> buildElectricityData() {
		 List<LwgyWaterRecord> lwgyElecRecords = lwgyElecRecordService.buildElectricityData();
		 return Result.OK("接收成功！",lwgyElecRecords);
	 }
*/

}
